package org.springblade.modules.notice.core;

import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.notice.core.channel.NoticeHandlerFactory;
import org.springblade.modules.notice.core.conditon.TriggerConditionStrategy;
import org.springblade.modules.notice.vo.NoticeTask;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Author ysq
 * @Date 2024/12/04
 * @Description 延迟消息通知处理入口
 */
@Slf4j
@Component
public class DelayProcess {
	@Resource
	private NoticeHandlerFactory noticeHandlerFactory;

	/**
	 * 延迟通知消息处理
	 * @param task
	 */
	@Async("noticeTaskExecutor")
	public void noticeBusinessProcess(NoticeTask task) {
		// 触发节点条件判断
		if (!TriggerConditionStrategy.get(task.getTriggerCondition()).isTrigger(task.getBizId())) {
			return;
		}
		// 分派到对应通知渠道执行器
		noticeHandlerFactory.getHandler(task.getChannelType()).doHandle(task);
	}
}
